<template>
  <div>
    <el-card shadow="always" :body-style="{ padding: '20px' }">
      <div slot="header">
        <el-button type="primary" size="default" @click="isShow = !isShow">新增</el-button>

      </div>
      <el-table :data="list" border stripe>
        <el-table-column
          prop="id"

          label="商品图片"
        >
          <template v-slot="scope">
            <img style="width:100px;height:100px;" :src="scope.row.pic" alt="">
          </template>
        </el-table-column>
        <el-table-column
          prop="id"

          label="商品图片"
        >
          <template v-slot="scope">
            <div>
              <p>开始时间:{{ scope.row.promotionStartTime }}</p>
              <p>结束时间:{{ scope.row.promotionEndTime }}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="time"

          label="是否过期"
        />
        <el-table-column
          prop="createTime"

          label="创建时间"
        />
      </el-table>

    </el-card>
    <el-dialog
      title="热销详情"
      :visible.sync="isShow"
      width="70%"
      @close=""
    >
      <Goods
        :is-show-label="true"
        :list="goodsList"
        :start="start"
        :limit="limit"
        :total="total"
        :brand-list="brandList"
        @search="search"
        @handle-size-change="handleSizeChange"
        @handle-current-change="handleCurrentChange"
        @close="close"
      />
      <span slot="footer">
        <el-button @click="">Cancel</el-button>
        <el-button type="primary" @click="">OK</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import {
  findAllRecommends
} from '@/api/market/activity'
import Goods from '@/components/Goods/index'
import mix from '@/mixins/index'
import {
  productsByPage,
  findAllBrand
} from '@/api/goodsManage/goodsList/index.js'
export default {
  components: {
    Goods
  },
  mixins: [mix],
  data() {
    return {
      list: [],
      goodsList: [],
      brandList: [],
      isShow: false,
      formData: {
        'brandId': '',
        'id': '',
        'name': '',
        'productCategoryId': '',
        'productSn': '',
        'publishStatus': '',
        'verifyStatus': ''
      }
    }
  },
  computed: {

  },
  created() {
    this.init1()
    this.init()
    findAllBrand()
      .then(res => {
        this.brandList = res.data.items
      })
  },
  mounted() {

  },
  methods: {
    close() {
      this.isShow = !this.isShow
      this.init1()
    },
    search(val) {
      console.log('子组件传递的数据', val)
      this.formData = val
      this.init()
    },
    init() {
      productsByPage(this.start, this.limit, this.formData)
        .then(res => {
          console.log(res)
          // res.data.rows.forEach(ele => {
          //   ele.radio = ''
          // })
          this.goodsList = res.data.rows
          this.total = res.data.total
        })
    },
    init1() {
      findAllRecommends()
        .then(res => {
          res.data.items.forEach(ele => {
            // ele.promotionEndTime  活动结束时间戳
            // new Date().getTime()  当前时间戳
            console.log(new Date(ele.promotionEndTime).getTime() - new Date().getTime())
            if (new Date(ele.promotionEndTime).getTime() - new Date().getTime() > 0) {
              ele.time = '否'
            } else {
              ele.time = '过期'
            }
          })
          this.list = res.data.items
        })
    }
  }
}
</script>

<style scoped lang="scss">

</style>
